var aid, uid, status, ws;
var pinglun = 0;
var dianzan = 0;
if(window.plus){
	ready();
}else{
	document.addEventListener('plusready' , ready, false);
}
function ready(){
	ws = plus.webview.currentWebview();
	uid = plus.storage.getItem('uid');//用户id
	status = plus.storage.getItem('status');
	//传值的内容显示
	$('.name').text(ws.name);
	$('.avatar').attr('src',getAvatar(ws.awsatar));
	$('.addtime').text(ws.addtime); 
	$('.content').html(ws.content);
	console.log(ws.pro);
	var list ='';
	if(ws.pro != ''){
		for (var i = 0; i < ws.pro.length; i++) { 
			$('.bbs-img').append('<div><img src="'+webRoot+ws.pro[i]+'" alt=""  data-preview-src="" data-preview-group="1"/></div>');
		}
	}
	pinglun = parseInt(ws.pingnum);
	$('.ping').text(pinglun);
	$('.zhuanfa').text(ws.zhuannum);
	dianzan = parseInt(ws.zannum);
	$('.zan').text(dianzan);
	//end
	oneBbs();
	//点赞
	$('.dianzan').click(function(){
		if(status != '2'){
			toast('您的身份暂未认证通过，不能进行此操作');return;
		}
		showWating();
		$.ajax({
			type:"get",
			url:apiRoot+"?m=home&c=bbs&a=Likes&aid="+aid+"&uid="+uid,
			dataType :'json',
			success : function(data){
//				console.log(JSON.stringify(data));
				plus.nativeUI.closeWaiting();
				if(data == 1){//点赞成功
					plus.webview.getWebviewById(ws.spage).reload();
					$('.dianzan').css('color','red');
					toast('点赞成功');
					dianzan++;//赞增加
					$('.zan').text(dianzan);
				}else if(data == -1){
					toast('不可重复点赞！');
				}
			},
			error :function(e){
				console.log(JSON.stringify(e));
				errortoast();
			}
		});
	})
	//评论
	$('.submit').click(function(){
		if(status != '2'){
			toast('您的身份暂未认证通过，不能进行此操作');return;
		}
		var cont = $('.cont').val();
		if(!cont.trim()){
			toast('内容为空！');return;
		}
		console.log(cont);
//		console.log(apiRoot+"?m=home&c=bbs&a=addPing&aid="+aid+"&uid="+uid+"&cont="+cont);return;
		showWating();
		$.ajax({
			type:"get",
			url:apiRoot+"?m=home&c=bbs&a=addPing&aid="+aid+"&uid="+uid+"&cont="+cont,
			dataType :'json',
			success : function(data){
				console.log(JSON.stringify(data));
				plus.nativeUI.closeWaiting();
				if(data > 0){//评论成功
					plus.webview.getWebviewById(ws.spage).reload();
					toast('评论成功');
					$('.cont').val('');
					pinglun++;//评论增加
					$('.ping').text(pinglun);
				}
			},
			error :function(e){
				console.log(JSON.stringify(e));
				errortoast();
			}
		});
	})
}
//获取单条铁杆圈信息
function oneBbs(){
//	console.log(apiRoot+"?m=home&c=bbs&a=oneBbs&aid="+aid+"&uid="+uid);
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=bbs&a=oneBbs",
		data : {
			aid : ws.aid,
			uid : uid
		},
		dataType : 'json',
		success : function(data){
			plus.nativeUI.closeWaiting();
//			console.log(JSON.stringify(data.formem));
			if(data.iszan == 1){
				$('.dianzan').css('color','red');
			}
			var str1 = '';var str2 = '';var str3 = '';
			if(data.remem){
				$.each(data.remem, function(k,v) {//评论
					str1 += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-1">'+
							'<div class="overflow-h">'+
								'<i><img src="'+getAvatar(v.avatar)+'"/></i>'+
								'<div>'+
									'<li><span>'+v.name+'</span></li>'+
									'<li class="mui-h6">'+v.time+'</li>'+
									'<li class="iconfont dianzan-2 mui-h6"></li>'+
								'</div>'+
							'</div>'+
							'<div class="font-14 text-pinglun">'+v.cont+'</div>'+
						'</div>';
				});
			}
			if(data.zanmem){
				$.each(data.zanmem, function(k1,v1) {//点赞
					str3 += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-1 table-view-cell-im">'+
							'<div class="overflow-h">'+
								'<i><img src="'+getAvatar(v1.avatar)+'"/></i>'+
								'<div>'+
									'<li><span>'+v1.name+'</span></li>'+
									'<li class="mui-h6">'+v1.time+'</li>'+
									'<li class="iconfont dianzan-2 mui-h6"></li>'+
								'</div>'+
							'</div>'+							
						'</div>';
					
				});
			}
			if(data.formem){
				$.each(data.formem, function(k2,v2) {//转发
					str2 += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-1 table-view-cell-im">'+
							'<div class="overflow-h">'+
								'<i><img src="'+getAvatar(v2.avatar)+'"/></i>'+
								'<div>'+
									'<li><span>'+v2.name+'</span></li>'+
									'<li class="mui-h6">'+v2.time+'</li>'+
									'<li class="iconfont dianzan-2 mui-h6"></li>'+
								'</div>'+
							'</div>'+							
						'</div>';
				});
			}
			$('#item1mobile').html(str1);//评论
			$('#item2mobile').html(str2);//转发
			$('#item3mobile').html(str3);//点赞
		},
		error : function(e){
			console.log(JSON.stringify(e));
		}
	});
}
var tt = setInterval(oneBbs,3000);